module Authorize::Authorize
  #普通用户
  def ordinary_user(user_params = current_user)
    user_params.add_role :ordinary
  end
  #管理员用户
  def admin_user(user_params = current_user,*options)
    if !options[:init].blank? && options[:init]==true
      user_params.add_role :admin_init
    else
      user_params.add_role :admin
    end

  end
  #游客
  def tourist_user(session_id=session[:_hua_session])

  end

  #注册时发生的权限变更事件
  module Registration_authorize_event
    include Authorize::Authorize
    #
    #注册时默认全部为普通用户。
    #
    #options:
    # session_id
    #
    #
    #
    def init_global_authorize(user_params,*options)
      if user_params.nil?
        if options[:session_id].blank?
          session_id = options[:session_id]
          tourist_user(session_id)
        else
          tourist_user
        end
        return
      end
        ordinary_user(user_params)

    end
  end
end